package com.mayikt.edu.controller;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.mayikt.edu.base.BaseApiController;
import com.mayikt.edu.base.BaseResponse;
import com.mayikt.edu.constant.MayiktConstants;
import com.mayikt.edu.core.cache.LocalCache;
import com.mayikt.edu.dto.resp.EduCourseClassRespDTO;
import com.mayikt.edu.entity.EduCourseClass;
import com.mayikt.edu.service.IEduCourseClassService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 前端控制器
 *
 * @author mayikt
 * @since 2023-10-12
 */
@RestController
@RequestMapping("/course")
@Slf4j
@ApiOperation(value = "课程分类", notes = "课程分类")
public class EduCourseClassController extends BaseApiController {
    @Autowired
    private IEduCourseClassService iEduCourseClassService;

    /**
     * 查询所有的课程分类
     *
     * @return
     */
    @GetMapping("/getAllCourseClass")
    @ApiOperation(value = "查询所有课程分类", notes = "查询所有课程分类")
    public BaseResponse getAllCourseClass() {
        List<EduCourseClassRespDTO> eduCourseClassRespList = new ArrayList<>();
        eduCourseClassRespList =
                LocalCache.get(MayiktConstants.COURSE_ALLCOURSECLASSLIST, eduCourseClassRespList);
        if (CollectionUtils.isEmpty(eduCourseClassRespList)) {
            log.error("[从集合中为查找到所有的课程分类数据]");
            return setResultError();
        }
        return setResultSuccessData(eduCourseClassRespList);
    }

    /**
     * 查询所有的课程分类
     *
     * @return
     */
    @GetMapping("/getAllCourseClass1")
    @ApiOperation(value = "查询所有课程分类", notes = "查询所有课程分类")
    public BaseResponse getAllCourseClass1() {
        List<EduCourseClass> allCourseClass = new ArrayList<>();
        allCourseClass = LocalCache.get(MayiktConstants.COURSE_ALLCOURSECLASSLIST, allCourseClass);
        if (CollectionUtils.isEmpty(allCourseClass)) {
            log.error("[从集合中为查找到所有的课程分类数据]");
            return setResultError();
        }
        return setResultSuccessData(allCourseClass);
    }
}
